<!-- *Author: 黄旗, *Date: 2020-08-04 15:45:59 -->
<template>
    <div>
        <Modal v-model='modal' :title="edit?'编辑新增目标网站':'新增目标网站'" :mask-closable='false' @on-cancel='canceledit(modalname)'>
            <Form :label-width='145' :ref='modalname' :model='modalparams' :rules='createRules'>
                <FormItem label='目标网站网址：' prop='source_url'>
                    <Input style="width: 280px" clearable v-model='modalparams.source_url' placeholder='请输入目标网站网址' />
                </FormItem>
                <FormItem label='栏目ID：' prop='id_data'>
                    <Input style="width: 280px" clearable v-model='modalparams.id_data' placeholder='请输入栏目ID，多个ID用逗号隔开' />
                </FormItem>
            </Form>
            <div slot='footer'>
                <Button @click='canceledit(modalname)'>取消</Button>
                <Button @click='submitedit(modalname)' type='primary'>保存</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
    import util from '@/libs/util';
    import { copyindexcopyarcadd, copyindexcopyarcedit } from '@api/copytext'
    import { getRoleList } from '@/api/powersetting.js';
    export default {
        name: '',
        components: {},

        data () {
            return {
                modalname: 'modalname',
                modal: false,
                edit: false,
                modalparams: { source_url: '', id_data: '', target_id: '' },
                createRules: {
                    source_url: [{
                        required: true,
                        message: '请输入目标网站网址',
                        trigger: 'blur'
                    }],
                    id_data: [{
                        required: true,
                        message: '请输入栏目ID，多个ID用逗号隔开',
                        trigger: 'blur'
                    }]
                }
            };
        },
        mounted () {
        },
        /* 函数方法集合 */
        methods: {
            /* @函数功能: 初始化 */
            initial (row) {
                this.$refs[this.modalname].resetFields();
                this.modalparams = { source_url: '', id_data: '', target_id: '' },
                this.askData(row)
            },
            askData (row) {
                this.modal = true
                this.edit = true
                if (row) {
                    this.modalparams.source_url = row.domain
                    this.modalparams.id_data = row.column_id
                    this.modalparams.target_id = row.id
                } else {
                    this.edit = false
                }
            },
            canceledit (name) {
                this.$refs[name].resetFields();
                this.modal = false
            },
            submitedit (name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        if (!this.edit) {
                            copyindexcopyarcadd(this.modalparams).then(() => {
                                this.$Message.success('新增成功')
                                this.modal = false
                                this.$emit('askData')
                            })
                        } else {
                            copyindexcopyarcedit(this.modalparams).then(() => {
                                this.$Message.success('编辑成功')
                                this.modal = false
                                this.$emit('askData')
                            })
                        }
                    }
                })
            }
        }
    }
</script>
